<?php
namespace app\common\model;

class Message extends Base
{
    public static function setMessage($userIds = 0, $objId = 0, $type = 1, $content = '')
    {
        if($userIds == 0) $userIds = User::getCol(['is_staff' => 1, 'status' => 1], 'id');

        if($type == 1){
            $noticeInfo = Notice::getFind(['id' => $objId]);
        }

        foreach($userIds as $userId){
            $info['user_id']     = $userId;
            $info['type']        = $type;
            $info['obj_id']      = $objId;
            $info['create_time'] = time();

            if($type == 1){
                $info['title']   = '通知公告';
                $info['content'] = '发布了新的通知:' . $noticeInfo['title'];
            }else{
                $info['title']   = '面试通过';
                $info['content'] = $content;
            }

            $param[] = $info;
        }

        self::addAll($param);
    }
}